﻿using System;
using System.Collections.Generic;
using System.Data.Common;
using System.Linq;
using System.Text;

using BlueCMS.Core.Data;
using BlueCMS.Core.Data.Query.Clauses;
using BlueCMS.Core.Data.Query.Columns;
using BlueCMS.Core.Data.Query.Conditions;
using BlueCMS.Core.Data.Query.Tables;
using BlueCMS.Core.Providers;

namespace BlueCMS.Core.Data.Query.Generator
{
    public abstract partial class QueryGeneratorBase
    {
        public virtual string ProcessDeleteQuery(DeleteClause delete, FromClause from, WhereClause where, Dictionary<string, DbParameter> parameters)
        {
            StringBuilder sb = new StringBuilder();
            GenerateDeleteStatement(delete, sb);
            if (from.Tables.Count > 0)
            {
                GenerateFromStatement(from, sb, parameters);
            }
            GenerateWhereStatement(where, sb, parameters);

            return sb.ToString();
        }

        protected virtual void GenerateDeleteStatement(DeleteClause clause, StringBuilder sb)
        {
            sb.Append("DELETE FROM ");
            GenerateTableName(clause.DeleteTable, sb);
            sb.Append(" ");
        }
    }
}
